package com.rongzhe.house.order.controller;

import com.rongzhe.house.common.resp.ApiResult;
import com.rongzhe.house.order.entity.CreateRequest;
import com.rongzhe.house.order.entity.GetSignRequest;
import com.rongzhe.house.order.service.OrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by hggxg on 2017/11/19.
 */
@RestController
@RequestMapping("order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "创建", notes = "订单", httpMethod = "POST")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ApiImplicitParam(name = "createRequest", value = "商品和数量", required = true, dataType = "CreateRequest")
    public ApiResult<String> create(@RequestBody CreateRequest createRequest) {

        ApiResult apiResult = new ApiResult();


        apiResult.setData(orderService.createOrder(createRequest.getHouseId(), createRequest.getCount()));


        return apiResult;

    }


    @ApiOperation(value = "获取第三方签名", notes = "订单", httpMethod = "GET")
    @RequestMapping(value = "/sign", method = RequestMethod.GET)
    @ApiImplicitParam(name = "signRequest", value = "订单号和支付类型", required = true, dataType = "GetSignRequest")
    public ApiResult<String> getSign(@RequestBody GetSignRequest signRequest) {

        ApiResult apiResult = new ApiResult();


        apiResult.setData(orderService.getSign(signRequest.getCode(), signRequest.getPayType()));


        return apiResult;

    }


    @ApiOperation(value = "结果查询", notes = "订单", httpMethod = "GET")
    @RequestMapping(value = "/result/query", method = RequestMethod.GET)
    @ApiImplicitParam(name = "signRequest", value = "订单号", required = true, dataType = "GetSignRequest")
    public ApiResult<String> queryResult(@RequestBody GetSignRequest signRequest) {

        ApiResult apiResult = new ApiResult();


        apiResult.setData(orderService.getSign(signRequest.getCode(), signRequest.getPayType()));


        return apiResult;

    }

}
